<?php

class Video extends CI_Controller {

    private static $layout_data = array();
    private static $home_data = array();
    
    function __construct()
    {
        parent::__construct();

        $this->load->model('node_model');
    }
	
    function index()
    {
        self::$home_data = array();
        self::$layout_data['page_title'] = 'Oneway.vn - Video';
        self::$layout_data['content'] = $this->load->view('video/index', self::$home_data, TRUE);
        $this->load->view('layouts/main', self::$layout_data);
    }

    /**
     * Get new video ajax
     */
    public function getBlockHomeVideo()
    {
        //Set params
        $parentID = $this->input->get('parentID')?$this->input->get('parentID'):4;
        $limit = $this->input->get('limit')?$this->input->get('limit'):7;
        $offset = $this->input->get('offset')?$this->input->get('offset'):0;

        //Get arrNode data and total
        $arrNode = $this->node_model->getListNodeByParentID($parentID, $limit, $offset);
        
        //Check arrNode
        if($arrNode['total'] > 0)
        {
            //Get newest node data
            $firstNode = $this->node_model->getNodeDetail($arrNode['data'][0]['node_id']);
        }

        //Set home data
        self::$home_data['firstNode'] = $firstNode;
        self::$home_data['arrNode'] = array_slice($arrNode['data'], 1);

        //Assign to view
        $this->load->view('video/video_block', self::$home_data);
    }

    /**
     * View detail function
     */
    public function view()
    {
        //Get nodeID
        $nodeID = $this->uri->segment(4);

        //Get note detail
        $nodeDetail = $this->node_model->getNodeDetail($nodeID);

        //Assign to view
        self::$home_data['node'] = $nodeDetail;
        self::$layout_data['page_title'] = $nodeDetail['title'];
        self::$layout_data['page_description'] = $nodeDetail['description'];
        self::$layout_data['page_thumb'] = $nodeDetail['thumb'];
        self::$layout_data['content'] = $this->load->view('video/view', self::$home_data, TRUE);

        //Load view
        $this->load->view('layouts/main', self::$layout_data);
    }

    /**
     * Get randome node
     */
    public function getRandVideo()
    {
        //Get params
        $categoryID = $this->input->get('categoryID');
        $limit = $this->input->get('limit');

        //Get data
        self::$home_data['arrNode'] = $this->node_model->getListRandNodeByCategoryID($categoryID, $limit);

        //Assign to view
        $this->load->view('video/rand_video_block', self::$home_data);
    }

    /**
     * Get list hot video
     */
    public function getHotVideo()
    {
        //Get params
        $categoryID = $this->input->get('categoryID');
        $limit = $this->input->get('limit')?$this->input->get('limit'):10;
        $offset = $this->input->get('offset')?$this->input->get('offset'):0;

        //Get data
        self::$home_data['category'] =  $this->input->get('category');
        self::$home_data['arrNode'] = $this->node_model->getListHotNodeByCategoryID($categoryID, $limit, $offset);

        //Assign to view
        $this->load->view('video/list_hot_video', self::$home_data);
    }

    /**
     * Get list new video
     */
    public function getNewVideo()
    {
        //Get params
        $categoryID = $this->input->get('categoryID');
        $category = $this->input->get('category');

        $page = $this->input->get('page')?$this->input->get('page'):1;
        $limit = $this->input->get('limit')?$this->input->get('limit'):10;
        $offset = ($page - 1) * $limit;

        //Get data
        self::$home_data['arrNode'] = $this->node_model->getListNodeByCategoryID($categoryID, $limit, $offset);
        self::$home_data['category'] =  $category;
        self::$home_data['categoryID'] =  $categoryID;
        self::$home_data['page'] =  $page;
        self::$home_data['limit'] =  $limit;
        self::$home_data['prefix'] =  $category = $this->input->get('prefix');

        //Assign to view
        $this->load->view('video/list_new_video', self::$home_data);
    }

}
